package com.handyshop.mall.auth.config.redis;

import com.handyshop.mall.auth.config.JwtTokenEnhancer;
import com.handyshop.mall.auth.constants.BaseOauthConstants;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;

/**
 * redis token实现
 *
 * @author handy
 * @date 2020/11/12 15:16
 */
@RequiredArgsConstructor
public class RedisTokenConfig {
    private final RedisConnectionFactory redisConnectionFactory;

    /**
     * 配置TokenStore redis
     *
     * @return TokenStore
     */
    @Bean
    public TokenStore redisTokenStore() {
        RedisTokenStore tokenStore = new RedisTokenStore(redisConnectionFactory);
        tokenStore.setPrefix(BaseOauthConstants.PROJECT_OAUTH_ACCESS);
        return tokenStore;
    }

    /**
     * 配置jwt增强
     *
     * @return TokenEnhancer
     */
    @Bean
    public TokenEnhancer jwtTokenEnhancer() {
        return new JwtTokenEnhancer();
    }

}
